﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace DataShow.codeDAL
{
    public class Common
    {
        #region 构造函数
        SqlHelper sqlhelper;
        public Common()
        {
            sqlhelper = new SqlHelper();
        } 
        #endregion


        #region 抽象搜索（带分页）
        /// <summary>
        /// 抽象搜索（带分页）
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="pagesize">页大小</param>
        /// <param name="pageindex">页码</param>
        /// <param name="condition">搜索条件</param>
        /// <param name="columnName">列名</param>
        /// <returns>DataTable</returns>
        public DataTable Search(string tableName, int pagesize, int pageindex, string condition,string columnName,string order="id")
        {
            DataTable dt = new DataTable();
            string procname = "proc_ShowPage";
            SqlParameter[] paras = new SqlParameter[] 
            {
                new SqlParameter("@tblName",tableName as object),
                new SqlParameter("@strGetFields","*" as object),
                new SqlParameter("@strOrder",order as object),
                new SqlParameter("@strOrderType","desc" as object),
                new SqlParameter("@PageSize",pagesize as object),
                new SqlParameter("@PageIndex",pageindex as object),
                new SqlParameter("@strWhere",condition as object),
            };
            dt = sqlhelper.ExecuteQuery(procname, paras, CommandType.StoredProcedure);
            return dt;
        } 
        #endregion

        #region 获得所有天气类型
        /// <summary>
        /// 获得所有天气类型
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllWeathers()
        {
            string sql = "select * from Weather_code";
            return sqlhelper.ExecuteQuery(sql, CommandType.Text);
        } 
        #endregion
    }
}